
//首页js
var jwx_nhi = {
    start:function(){
        this.jq();
        this.zengxianbtn();//赠险判断是否领取
    },
    jq:function(){
        var bannerHd  = $("#jwx_nhi_banner .hd"),bannerHd2  = $("#jwx_nhi_huoban .hd");
        TouchSlide({
            slideCell:"#jwx_nhi_banner",
            titCell:"#jwx_nhi_banner .hd",
            mianCell:"#jwx_nhi_banner .bd",
            autoPlay:true,
            autoPage:true,
            switchLoad:"_src",
            effect:"leftLoop"
        });
        TouchSlide({
            slideCell:"#jwx_nhi_huoban",
            titCell:"#jwx_nhi_huoban .hd",
            mianCell:"#jwx_nhi_huoban .bd",
            autoPlay:true,
            autoPage:true,
            switchLoad:"_src",
            effect:"leftLoop"
        });
        bannerHd.css("marginLeft",-((bannerHd.width()/2)+5));
        bannerHd2.css("marginLeft",-((bannerHd2.width()/2)+5));
    },
    zengxianbtn:function(){
        var div = $("#jwx_zx_productList");
        $.get("/wxpersonal/ajaxGetUserFreeAgained",{},function(data){
            data = JSON.parse(data);
            if(data.code == 0){
                for(var i = 0; i < data.data.length; i++){
                    if(data.data[i].isgain == 1){
                        div.find(".btn_"+data.data[i].productid).find(".a1").addClass("a2");
                        div.find(".btn_"+data.data[i].productid).find("a").removeAttr("href");
                    }
                }
            }
        });
    }
};
//资质证件
var jwx_zz = {
    start:function(){
        this.jq();
    },
    jq:function(){
        var jwx_zz_dl = $("#jwx_zz_dl");
        jwx_zz_dl.find("img").bind("click",function(){
            $.bigImg(this);
        });
    }
}

//三分钟看穿保险
var jwx_sfz = {
    start:function(){
        this.jq();
    },
    jq:function(){
        var div = $("#jwx_sfz_mian");
        TouchSlide({
            slideCell:"#jwx_sfz_mian",
            titCell:"#jwx_sfz_mian .hd li",
            mianCell:"#jwx_sfz_mian .bd",
            endFun:function(index){
                div.find(".bd").height(div.find(".bd li").eq(index).find("table").height()+70);
            }
        });
    },
    tabClick:function(obj){
        var div = $("#jwx_sfz_mian");
        var $this = $(obj),conter = $this.next().find(".conter");
        if($this.hasClass("on")){
            $this.removeClass("on");
            conter.animate({"height":0},100);
        }else{
            $this.addClass("on");
            conter.animate({"height":conter.find("div").height()},100);
        }
        setTimeout(function(){
            div.find(".bd").height(div.find(".bd li").eq(div.find(".hd .on").index()).find("table").height()+70);
        },500)
    }
};

//消息中心
var jwx_message = {
    jq:function(){
        var list = $("#jwx_message_list");
        if(list.length > 0){
            jwx_message.requests();
            $(window).scroll(function(){
                if(list.attr("data-load") == "true" && $.scrollBottom()){
                    jwx_message.requests();
                }
            });
        }
    },
    requests:function(){
        var div = $("#jwx_message_list"),
            loading = div.find(".loading"),
            typeText = {
                name:["","续保","优惠券","优惠券","支付提示","活动提示","回复提示","回复提示"],
                buttonText:["","立即续保","立即购买","立即购买","立即支付","立即查看"],
                class:["","li1","li2","li2","li3","li4","li5","li5"]
            },url = "";
        if(div.attr("data-load") == "true"){
            if(div.find("li").length < 2){
                loading.css("margin-top","50%").show();
            }else{
                loading.css("margin-top","0").show();
            }
            div.attr("data-load",false);
            $.get("/message/ajaxMessageList",{page:div.attr("data-page")},function(data){
                data = JSON.parse(data);
                loading.hide();
                if(data.code == 0){
                    if(data.data.list.length > 0){
                        loading.hide();
                        div.attr("data-page",parseInt(div.attr("data-page"))+1);
                        div.attr("data-load",true);
                        var html = "",listI = "";
                        for(var i = 0;i < data.data.list.length;i++){
                            listI = data.data.list[i];
                            if(listI.type == 2 || listI.type == 3){
                                url = '<a href="/wxpersonal/coupons">'+typeText.buttonText[listI.type]+'</a>';
                            }else if(listI.type == 5){
                                url = '<a href="'+listI.url+'">'+typeText.buttonText[listI.type]+'</a>';
                            }else{
                                url = "";
                            }
                            html += '<li data-read="'+listI.is_read+'" class="'+typeText.class[listI.type]+'">'+
                            '<div class="d1">'+typeText.name[listI.type]+'</div>'+
                            '<div class="d2">'+listI.content+'</div>'+url+'</li>';
                        }
                        loading.before(html);
                    }else{
                        if(div.attr("data-page") == 1){
                            $("#jwx_message_kong").show();
                        }
                    }
                }else{
                    alert(data.error);
                }
            });
        }
    }
}